package com.valley.dream.tihai.util.network;

import com.valley.dream.tihai.model.entity.Type;
import com.valley.dream.tihai.service.ProblemService;
import com.valley.dream.tihai.service.TypeService;

import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class RetrofitUtil {

//    private static final String ip = "http://118.178.105.89:8888/tihai/";
    private static final String ip = "http://192.168.124.2:8888/tihai/";

    public static Retrofit getRetrofit(){
        Retrofit retrofit = new Retrofit
                .Builder()
                .baseUrl(ip)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        return retrofit;
    }

    public static Retrofit retrofit;

    static {
        retrofit = new Retrofit
                .Builder()
                .baseUrl(ip)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }


    public static ProblemService getProblemService(){
        ProblemService service = retrofit.create(ProblemService.class);
        return service;
    }

    public static TypeService getTypeService(){
        return retrofit.create(TypeService.class);
    }

    public static <T> Object getRetrofit(T t){
        Retrofit retrofit = new Retrofit
                .Builder()
                .baseUrl(ip)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        return retrofit.create(t.getClass());
    }

}
